﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using VK.Comm;
using System.Web;

namespace VK.Casemeet.Articles
{
    public static class ArticleHelper
    {
        public static void BindCategoryDDL(DropDownList ddl, OptionType optionType)
        {
            ddl.Items.Clear();
            ddl.DataSource = CategoryBLL.GetCategoryArray();
            ddl.DataTextField = "Name";
            ddl.DataValueField = "CategoryID";
            ddl.DataBind();
            switch (optionType)
            {
                case OptionType.Default: break;
                case OptionType.Search: ddl.Items.Insert(0, new ListItem("全部", "0")); break;
                case OptionType.Select: ddl.Items.Insert(0, new ListItem("请选择", "0")); break;
            }
            ddl.SelectedIndex = 0;
        }

        public static string[] GetItems(string text)
        {
            string blank = HttpUtility.UrlDecode(" ");
            string[] items = text.Trim().Split(new string[1] { blank }, StringSplitOptions.RemoveEmptyEntries);

            return items;
        }

        public static string[] GetContainKeywordArray(string containAllKeyword, string containAnyKeyword)
        {
            List<string> containKeyword = new List<string>();
            containKeyword.AddRange(ArticleHelper.GetItems(containAllKeyword));
            containKeyword.AddRange(ArticleHelper.GetItems(containAnyKeyword));

            return containKeyword.ToArray();
        }

        public static string[] GetContainAllKeywordArray(string containAllKeyword)
        {
            return ArticleHelper.GetItems(containAllKeyword);
        }

        public static string[] GetContainAnyKeywordArray(string containAnyKeyword)
        {
            return ArticleHelper.GetItems(containAnyKeyword);
        }

        public static string[] GetLocationArray(string location)
        {
            return ArticleHelper.GetItems(location);
        }
    }
}
